package com.itheima.config;

import com.itheima.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//Web环境下的配置类
//@Configuration是否要注释
@Configuration
public class WebConfig implements WebMvcConfigurer {

    //注入拦截器
    @Autowired
    LoginInterceptor loginInterceptor;

    //重写添加拦截器的方法addInterceptors
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor) //添加拦截器
                .addPathPatterns("/**")  //设置拦截器拦截路径
                .excludePathPatterns("/login"); //设置不拦截的路径
    }
}
